﻿#region Header
/********************************************************           
 * StatusMessage      
 *                                                         
 * Author:  Richard Barclay  (phphanatic at gmail dot com) 
 * 
 * Copyright: 2009 Richard Barclay
 * 
 * License: GNU General Public License (GPL)
 *     
 * This file is part of the Intergr8.GoogleVisualization library.
 *
 *   The Intergr8.GoogleVisualization library is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *  Intergr8.GoogleVisualization library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Intergr8.GoogleVisualization library.  If not, see <http://www.gnu.org/licenses/>.
 *                                                         
 * Purpose:  Maintain a single Google Visualisation API Status Message
 *                                                         
 * Usage:                                                  
 *      Construct with a mandatory reason and optional Message and Detail
 *      
 ********************************************************/
#endregion



namespace Intergr8.GoogleVisualization
{

    using System;
    using System.Collections.Generic;
    using System.Text;

    /// <summary>
    /// StatusMessage maintains the attributes required for an Error and Warning informational string
    /// 
    /// The output JSON string is formatted within the object
    /// </summary>
   internal class StatusMessage
   {
       #region Attributes
       /// <summary>
       /// Status reason
       /// </summary>
       private string _reason = "";
       /// <summary>
       /// Status message
       /// </summary>
       private string _message = "";
       /// <summary>
       /// Status message detail
       /// </summary>
       private string _detailMessage = "";
       #endregion

       /// <summary>
       /// Private constructor to control creation
       /// </summary>
       protected StatusMessage()
       {
       }

       /// <summary>
       /// Create with a single Reason string
       /// </summary>
       /// <param name="reason">String deascription of the message reason</param>
       public StatusMessage(string reason)
       {
           init(reason, "", "");
       }

       /// <summary>
       /// Construct with a reason and additional message
       /// </summary>
       /// <param name="reason">String description of the message reason</param>
       /// <param name="message">Additional message detail</param>
       public StatusMessage(string reason, string message)
       {
            init(reason, message,"");
       }

       /// <summary>
       /// Construct with a reason, an additional message and any extended message detail
       /// </summary>
       /// <param name="reason">String description of the message reason</param>
       /// <param name="message">Additional message detail</param>
       /// <param name="exMessage">Extended message information</param>
       public StatusMessage(string reason, string message, string detailMessage)
       {
           init(reason, message, detailMessage);
       }

       /// <summary>
       /// Internal initialisation of attributes from the constructors
       /// </summary>
       /// <param name="reason">String description of the message reason</param>
       /// <param name="message">Additional message detail</param>
       /// <param name="exMessage">Extended message information</param>
       private void init(string reason, string message, string detailMessage)
       {
           _reason = reason;
           _message = message;
           _detailMessage = detailMessage;
       }

       /// <summary>
       /// Convert the message object to a JSON format
       /// </summary>
       /// <returns></returns>
       public string toJSON()
       {
           string ret = "";

           string format = "{{reason:'{0}',message:'{1}',detailed_message:'{2}'}}";

           ret = String.Format(format, _reason, _message, _detailMessage);

           return ret;
       }
    }
}
